home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C14 / Ninherit.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  947 b   |  39 lines

  1. //: C14:Ninherit.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Non-inherited functions
  7. #include <fstream>
  8. using namespace std;
  9. ofstream out("ninherit.out");
  10.  
  11. class Root {
  12. public:
  13.   Root() { out << "Root()\n"; }
  14.   Root(Root&) { out << "Root(Root&)\n"; }
  15.   Root(int) { out << "Root(int)\n"; }
  16.   Root& operator=(const Root&) {
  17.     out << "Root::operator=()\n";
  18.     return *this;
  19.   }
  20.   class Other {};
  21.   operator Other() const {
  22.     out << "Root::operator Other()\n";
  23.     return Other();
  24.   }
  25.   ~Root() { out << "~Root()\n"; }
  26. };
  27.  
  28. class Derived : public Root {};
  29.  
  30. void f(Root::Other) {}
  31.  
  32. int main() {
  33.   Derived d1;  // Default constructor
  34.   Derived d2 = d1; // Copy-constructor
  35. //! Derived d3(1); // Error: no int constructor
  36.   d1 = d2; // Operator= not inherited
  37.   f(d1); // Type-conversion IS inherited
  38. } ///:~
  39.